home *** CD-ROM | disk | FTP | other *** search
Text File | 1999-06-16 | 4.9 KB | 152 lines | [TEXT/CWIE] |
- /*
- File: StNavServices.h
-
- Copyright: © 1998 by Apple Computer, Inc., all rights reserved.
-
- */
-
- // Stack Based classes for Navigation Services calls - NavGetFile, NavPutFile
-
- //
- // You may incorporate this sample code into your applications
- // without restriction. This sample code has been provided "AS
- // IS" and the responsibility for its operation is 100% yours.
- // You are not permitted to redistribute the source as "Apple
- // sample code" after having made changes. If you're going to
- // re-distribute the source, we require that you make it clear
- // in the source that the code was descended from Apple sample
- // code, but that you've made changes.
- //
-
- #ifndef __NAVIGATION__
- #include <Navigation.h>
- #endif
-
- #ifndef _H_UMemoryMgr
- #include <UMemoryMgr.h>
- #endif
-
- #include <Types.h>
- #include <Files.h>
- #include <stdarg.h>
-
-
- // provides automatic disposal of NavReplyRecord
- class StNavReplyDeleter
- {
- public:
- StDeleter<NavReplyRecord> data;
- ~StNavReplyDeleter ( ) { if ( data.IsOwner() ) NavDisposeReply ( data.Get() ); }
- };
-
-
- // a convenient callback for opening files
- typedef pascal OSErr (*StNavGetFile_OpenEventHandler) ( FSSpecPtr openSpec );
-
- enum {
- StNavGetFileOpenProcInfo = kPascalStackBased
- | RESULT_SIZE(SIZE_CODE(sizeof(OSErr)))
- | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(FSSpecPtr)))
- };
-
- #if GENERATINGCFM
- typedef UniversalProcPtr StNavGetFileOpenEventUPP;
- #else
- typedef StNavGetFile_OpenEventHandler StNavGetFileOpenEventUPP;
- #endif
-
- #if GENERATINGCFM
- #define NewStNavGetFileOpenProc(userRoutine) \
- (StNavGetFileOpenEventUPP) NewRoutineDescriptor((ProcPtr)(userRoutine), StNavGetFileOpenProcInfo, GetCurrentArchitecture())
- #else
- #define NewStNavGetFileOpenProc(userRoutine) \
- ((StNavGetFileOpenEventUPP) (userRoutine))
- #endif
-
- class StNavGetFile
- {
- public:
- // open file(s) with most NavGetFile options available
- // result - of the call
- // specs - ptr to user's FSSpecArrayPtr
- // if given:
- // if (getOneFile) then gets written with pointer to FSSpecArray of opened file(s)
- // else gets single FSSpec data written to the address (in specs)
- // numspecs - ptr to number of files opened
- // openProc - gets called for each file opened
- // reply - user's NavReplyRecord
- // user must call NavDisposeReply after using data in reply
- // *** ONE of the above (openPrec, specs, reply) MUST be supplied
- // getOneFile - set to true (default) if only one file wanted
- // showAllReadableFiles - set to true (default) if all readable files should be shown
- // eventProc, eventProcUD, previewProc, filterProc (see Programming with Navigation Services documentation)
- // typeList - user's list of files that can be opened
- // if nil, attempts to use default (open resource, see I.M. Translation Mgr.)
- StNavGetFile ( OSErr *result,
- void *specs = nil,
- long *numspecs = nil,
- StNavGetFileOpenEventUPP openProc = nil,
- NavReplyRecord *reply = nil,
- Boolean getOneFile = true,
- Boolean showAllReadableFiles = true,
- NavEventUPP eventProc = nil,
- NavPreviewUPP previewProc = nil,
- NavObjectFilterUPP filterProc = nil,
- NavTypeListHandle typeList = nil,
- NavCallBackUserData eventProcUD = 0L );
-
- virtual ~StNavGetFile ( );
-
- // create a NavTypeListHandle from a variable list of file types
- // if applSignature is 0L, use current process info signature
- static NavTypeListHandle MakeTypeList ( OSType applSignature, int numTypes, ... );
-
- // create a NavTypeListHandle from a static list of file types
- // if applSignature is 0L, use current process info signature
- static NavTypeListHandle MakeTypeList ( OSType applSignature, int numTypes, OSType *types );
-
- static void GetFSSpecFromAEDesc ( AEDesc &inDesc, FSSpec &outValue );
-
- friend class StNavPutFile;
- protected:
- static OSErr Init ( );
- static OSType GetApplSignature ( );
-
- NavDialogOptions fdialogOptions;
- FSSpecArrayPtr fTheirSpecs;
- StNavReplyDeleter fReply;
- NavEventUPP fTheirEventUPP;
- NavCallBackUserData fTheirEventUD;
- };
-
- class StNavPutFile
- {
- public:
- // save a file
- // result - of the call
- // fileType - of the file
- // fileCreator - of the file
- // fileType & fileCreator are used to formulate translation options
- // (see Programming with Navigation Services, NavPutFile)
- // spec - optional pointer to FSSpec of file
- // reply - user's NavReplyRecord (destructor will dispose of it)
- // eventProc, eventProcUD to handle events during dialog (see Programming with Navigation Services)
- StNavPutFile ( OSErr *result,
- OSType fileType,
- OSType fileCreator,
- FSSpecPtr spec = nil,
- NavReplyRecord *reply = nil,
- NavEventUPP eventProc = nil,
- NavCallBackUserData eventProcUD = 0L );
-
- // takes care of finishing the save process (calls NavCompleSave, NavDisposeReply)
- virtual ~StNavPutFile ( );
-
- protected:
- OSErr *fresult;
- NavDialogOptions fdialogOptions;
- StNavReplyDeleter fReply;
- NavEventUPP fTheirEventUPP;
- NavCallBackUserData fTheirEventUD;
- };
-